<template>
  <el-container class="home-container">
    <!-- 头部区 -->
    <el-header>
      <div>
        <span class="logo">和翔</span>
        <span>后台管理系统</span>
      </div>
      <van-icon name="wap-home" size="1rem" @click="gohome" />
      <el-button type="info" @click="logout">退出</el-button>
    </el-header>
    <!-- 页面主体区 -->
    <el-container>
      <!-- 侧边栏 -->
      <el-aside :width="iscollapse ? '64px' : '200px'">
        <div class="toggle-button" @click="toggleCollapse">|||</div>
        <!-- 侧边栏菜单区 -->
        <el-menu
          background-color="#333744"
          text-color="#fff"
          active-text-color="#409EFF"
          unique-opened
          :collapse="iscollapse"
          :collapse-transition="false"
          router
          :default-active="$route.path"
        >
          <!-- 一级菜单 -->
          <el-submenu
            :index="item.id + ''"
            v-for="item in menulist"
            :key="item.id"
          >
            <!-- 一级菜单模板区 -->
            <template slot="title">
              <!-- 图标 -->
              <i :class="iconsObj[item.id]"></i>
              <!-- 文本 -->
              <span>{{ item.authName }}</span>
            </template>
            <!-- 二级菜单 -->
            <el-menu-item
              :index="'/' + subItem.path"
              v-for="subItem in item.children"
              :key="subItem.id"
            >
              <template slot="title">
                <!-- 图标 -->
                <i class="el-icon-menu"></i>
                <!-- 文本 -->
                <span>{{ subItem.authName }}</span>
              </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <!-- 右侧主体 -->
      <el-main>
        <!-- 路由占位符 -->
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data() {
    return {
      // 菜单列表
      menulist: [
        {
          id: 101,
          authName: "订单管理",
          path: "orders",
          children: [
            {
              id: 102,
              authName: "和分期",
              path: "hfq",
              children: [],
              order: null,
            },
            {
              id: 103,
              authName: "和目",
              path: "hm",
              children: [],
              order: null,
            },
            {
              id: 104,
              authName: "宽带",
              path: "pppoe",
              children: [],
              order: null,
            },
            {
              id: 105,
              authName: "代销购机",
              path: "sellbuy",
              children: [],
              order: null,
            },
            {
              id: 106,
              authName: "以老带新",
              path: "oldWN",
              children: [],
              order: null,
            },
          ],
          order: 1,
        },
        {
          id: 141,
          authName: "业务查询",
          path: "search",
          children: [
            {
              id: 142,
              authName: "宽带查询",
              path: "spppoe",
              children: [],
              order: null,
            },
          ],
        },
        {
          id: 131,
          authName: "礼品仓库",
          path: "goods",
          children: [
            {
              id: 135,
              authName: "出入库",
              path: "hqgoods",
              children: [],
              order: null,
            },
            {
              id: 132,
              authName: "礼品统计",
              path: "goods",
              children: [],
              order: null,
            },
            {
              id: 133,
              authName: "申请列表",
              path: "myapplie",
              children: [],
              order: null,
            },
            {
              id: 134,
              authName: "使用详情",
              path: "goodapplie",
              children: [],
              order: null,
            },
          ],
          order: 1,
        },
        {
          id: 111,
          authName: "用户管理",
          path: "users",
          children: [
            {
              id: 112,
              authName: "用户列表",
              path: "users",
              children: [],
              order: null,
            },
          ],
          order: 1,
        },
        {
          id: 121,
          authName: "数据报表",
          path: "reports",
          children: [
            {
              id: 122,
              authName: "员工统计",
              path: "usersreports",
              children: [],
              order: null,
            },
            {
              id: 123,
              authName: "和分期",
              path: "hfqreports",
              children: [],
              order: null,
            },
          ],
          order: 2,
        },
      ],
      // 菜单图标
      iconsObj: {
        101: "iconfont icon-danju",
        111: "iconfont icon-users",
        121: "iconfont icon-tijikongjian",
        131: "iconfont icon-shangpin",
        141: "el-icon-search",
      },
      // 侧边栏伸缩
      iscollapse: false,
    };
  },
  created() {},
  methods: {
    // 退出功能
    logout() {
      window.localStorage.clear();
      this.$router.push("/login");
      this.$message.success("注销成功");
    },
    // 点击按钮,折叠或展开菜单
    toggleCollapse() {
      this.iscollapse = !this.iscollapse;
    },
    //
    gohome() {
      this.$router.push("/welcome");
    },
  },
};
</script>

<style lang="less" scoped>
.home-container {
  height: 100%;
}

.el-header {
  background-color: #373d41;
  display: flex;
  justify-content: space-between;
  padding-left: 0;
  align-items: center;
  color: #fff;
  font-size: 20px;
  > div {
    display: flex;
    align-items: center;
  }
}

.el-aside {
  background-color: #333744;
  .el-menu {
    border-right: none;
  }
}

.el-main {
  background-color: #eaedf1;
}

.iconfont {
  margin: 10px;
}
.el-icon-search {
  margin: 7px;
}

.toggle-button {
  background-color: #4a5064;
  font-size: 10px;
  line-height: 24px;
  color: #fff;
  text-align: center;
  letter-spacing: 0.2em;
  cursor: pointer;
}
.van-icon {
  cursor: pointer;
}
.van-icon:hover {
  color: #333744;
}

.logo {
  margin-left: 20px;
  width: 50px;
  height: 50px;
  border-radius: 25px;
  text-align: center;
  line-height: 50px;
  font-family: "微软雅黑", "Dosis", sans-serif;

  text-shadow: 0px 1px 0px #c0c0c0, 0px 2px 0px #b0b0b0, 0px 3px 0px #a0a0a0,
    0px 4px 0px #909090, 0px 5px 10px rgba(0, 0, 0, 0.6);
}

.logo {
  font-weight: bold;
  animation: myfirst2 15s infinite linear;
}
@keyframes myfirst2 {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(359deg);
  }
}

@keyframes myfirst {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(-359deg);
  }
}
</style>